package com.bw.network

import com.zyj.retrofit.adapter.FlowCallAdapterFactory
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

abstract class BaseHttpRetrofitlmpl : HttpRetrofit {

    protected open fun createokHttpBuilder(): OkHttpClient.Builder? {
        val builder = OkHttpClient.Builder()
        val loggingInterceptor = HttpLoggingInterceptor()
        loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
        builder.addInterceptor(loggingInterceptor)
            .readTimeout(readtime(), TimeUnit.SECONDS)
            .connectTimeout(connectime(), TimeUnit.SECONDS)
            .writeTimeout(writetime(), TimeUnit.SECONDS)
        return builder
    }

    protected abstract fun readtime(): Long
    protected abstract fun connectime(): Long
    protected abstract fun writetime(): Long
    override fun createRetrofit(client: OkHttpClient?): Retrofit {
        val builder = Retrofit.Builder()
        builder.client(client)
            .baseUrl(ApiConst.BASEURL)
            .addCallAdapterFactory(FlowCallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
        return builder.build()
    }
}